#include "unpc.h"

void put(struct prodcons *b, int data)
{
    pthread_mutex_lock(&b->lock);
    if((b->writepos+1)%BUFFER_SIZE== b->readpos)
    {
        pthread_cond_wait(&b->notfull,&b->lock);
    }
    b->buffer[b->writepos] = data;
    b->writepos++;
    if (b->writepos >= BUFFER_SIZE)
    {
        b->writepos = 0;
    }
    pthread_cond_signal(&b->notempty);
    pthread_mutex_unlock(&b->lock);
}


void *producer(void *data)
{
    int n;

    for (n = 0; n < 100; n++)
    {
        printf("%d ", n);
        put(&buffer,n);
    }
    put(&buffer, OVER);
    return NULL;
}


